﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "CmdDrawWall.h"
#include "CommandIds.h"
#include "../UIPlatform/CommandRegister.h"
#include "IAction.h"
#include "IDocument.h"
#include "Action/ActionDrawWall.h"
#include "UiDocumentViewUtils.h"
#include "IUserTransaction.h"
#include "Wall/Wall.h"
#include "IGraphicsBRepBody.h"
#include "IGraphicsElementShape.h"
#include "IPureGraphicsElement.h"
#include "EnableCompileWarning_The_LAST_IncludeInCpp.h" 


using namespace Sample;
using namespace gcmp;

REGISTER_COMMAND(CmdDrawWall)

CmdDrawWall::CmdDrawWall() : CommandBase(ID_CMD_DRAW_WALL)
{

}

CmdDrawWall::~CmdDrawWall()
{

}

bool CmdDrawWall::IsEnabled() const
{
    return UiDocumentViewUtils::GetCurrentDocument() != nullptr;
}

bool CmdDrawWall::IsVisible() const
{
    return UiDocumentViewUtils::GetCurrentDocument() != nullptr;
}

gcmp::OwnerPtr<gcmp::IAction> CmdDrawWall::ExecuteCommand(const gcmp::CommandParameters& cmdParams)
{
#if 1
    return NEW_AS_OWNER_PTR(ActionDrawWall);
#else
    IDocument *pDocument = UiDocumentViewUtils::GetCurrentDocument();
    OwnerPtr<IUserTransaction> opUserTransaction =
        IUserTransaction::Create(pDocument, GBMP_TR(L"绘制墙体"));
    Vector3d startPt({ -1000,0,0 }), endPt({ 1000,0,0 });
    Wall* pWall = Wall::Create(pDocument, startPt, endPt, ElementCreationOptions::Normal);
    DBG_WARN_UNLESS(pWall, L"Wall不能为空", L"GDMP", L"2023-09-30");

    OwnerPtr<IBody> opBody = pWall->MakeBody();
    OwnerPtr<IGraphicsBRepBody> opBrepBody = IGraphicsBRepBody::Create(TransferOwnership(opBody));

    //创建图形表达
    gcmp::OwnerPtr<IGraphicsElementShape> opGraphicsElementShape =
        IGraphicsElementShape::Create(GraphicsRenderLayer::Model);
    opGraphicsElementShape->AddChild(TransferOwnership(opBrepBody));
    IPureGraphicsElement* pPureGraphicsElement =
        IPureGraphicsElement::Create(pDocument, TransferOwnership(opGraphicsElementShape));
    opUserTransaction->Commit();

    return nullptr;
#endif
}